﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChurchData.Business;

namespace ChurchData
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
            lblNopeTryAgain.Text = "";
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            lblNopeTryAgain.Text = "Validating...";
            this.Refresh();
            Cursor.Current = Cursors.WaitCursor;
            EmployeeBO eBO = new EmployeeBO();
            if (eBO.ValidateLogin(this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim()))
            {
                this.DialogResult = DialogResult.OK;
                Cursor.Current = Cursors.Default;
                this.Close();
            }
            else
            {
                lblNopeTryAgain.Text = "Nope, try again";
                this.txtPassword.Text = "";
                this.DialogResult = DialogResult.No;
                Cursor.Current = Cursors.Default;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void txtPassword_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                this.btnLogin.PerformClick();
        }
    }
}
